package com.fauks.ssm.springmvc.annotation;

import com.fauks.ssm.springmvc.exception.NameException;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyExceptionResolver implements HandlerExceptionResolver {

    //无论发生什么异常都会走该方法
    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        ModelAndView modelAndView = new ModelAndView();
        //存放异常一心
        modelAndView.addObject("ex", ex);
        if (ex instanceof NameException) {
            //do something
        }
        return modelAndView;
    }
}
